package dns

import (
	"net"
	"strings"
)

type DNSMXData struct {
	address string
	host    string
	mxs     []*net.MX
}

//
func NewMxData(address string) *DNSMXData {
	return &DNSMXData{address: address, host: "", mxs: nil}
}
func (mx *DNSMXData) LookUpMx() (string, error) {
	host := strings.Split(mx.address, "@")
	mx.host = host[len(host)-1]
	//
	mxs, err := net.LookupMX(mx.host)
	mx.mxs = mxs
	h := mx.mxs[0].Host
	return h[:len(h)-1], err
}
